package com.sgb.kjwl.view.ui.fragment.manage;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;

import com.sgb.kjwl.AppFragment;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.FragmentShopCompanyManageBinding;

import java.util.ArrayList;
import java.util.List;

public class ShopCompanyManageFragment extends AppFragment {

    FragmentShopCompanyManageBinding binding;
    private String companyNo;
    private String[] tag = {"经营动态","专项资质","荣誉荣耀","知识产权","专项资产"};
    private int childPosition;

    public static ShopCompanyManageFragment newInstance(String companyNo,int childPosition) {
        ShopCompanyManageFragment fragment = new ShopCompanyManageFragment();
        Bundle bundle = new Bundle();
        bundle.putString("companyNo", companyNo);
        bundle.putInt("childPosition", childPosition);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(inflater, R.layout.fragment_shop_company_manage, container, false);
        if (getArguments() != null) {
            companyNo = getArguments().getString("companyNo");
            childPosition = getArguments().getInt("childPosition");
        }
        return binding.getRoot();
    }


    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView();
    }

    protected void initView() {
        List<Fragment> list = new ArrayList<>();
        list.add(ShopCompanyTrendsFragment.newInstance(companyNo));
        list.add(SpecialQualificationFragment.newInstance(companyNo));
        list.add(TradeHonourFragment.newInstance(companyNo));
        list.add(IntellectualPropertyRightMainFragment.newInstance(companyNo));
        list.add(CompanyPropertyFragment.newInstance(companyNo));
        binding.vpShopCompanyManage.setAdapter(new FragmentPagerAdapter(getChildFragmentManager()) {
            @NonNull
            @Override
            public Fragment getItem(int position) {
                return list.get(position);
            }

            @Override
            public int getCount() {
                return list.size();
            }

            @Nullable
            @Override
            public CharSequence getPageTitle(int position) {
                return tag[position];
            }
        });

        binding.tlShopCompanyManage.setupWithViewPager(binding.vpShopCompanyManage);
        binding.vpShopCompanyManage.setCurrentItem(childPosition);
    }

}
